package org.elasticsearch.plugin.helloworld;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;

import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.Loggers;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.AbstractPlugin;
import org.elasticsearch.rest.RestModule;

public class HelloWorldPlugin extends AbstractPlugin {
	final ESLogger logger = Loggers.getLogger(getClass());

	@Override
	public String name() {
		return "HelloWorld";
	}

	@Override
	public String description() {
		return "Hello World Plugin";
	}
	
	@Override
	public void processModule(Module module) {
		logger.info(String.format("################ process module %s #################", module.getClass().getName()));
		if(module instanceof RestModule) {
			((RestModule)module).addRestAction(HelloWorldHandler.class);
		}
		
		if(module instanceof HelloModule) {
			logger.info("############## process hello module #####################");
		}
	}
	
	@Override
	public Collection<Module> modules(Settings settings) {
		HelloModule helloModule = new HelloModule();
		ArrayList<Module> list = new ArrayList<>();
		list.add(helloModule);
		Collections.unmodifiableList(list);
		return list;
	}
	
	@SuppressWarnings("rawtypes")
	@Override
	public Collection<Class<? extends LifecycleComponent>> services() {
		Collection<Class<? extends LifecycleComponent>> list = new ArrayList<>();
		list.add(HelloService.class);
		return list;
	}
	
}
